import 'package:core_package/ui/widget/my_asset_image.dart';
import 'package:flutter/material.dart';
import 'package:core_package/core_package.dart';

//两种方法都可以实现  在弹框上面增加关闭按钮
mixin BaseCenterAlertWidget {
  Widget buildCloseAlertWidget(
    BuildContext context, {
    @required Widget? child,
    double? width,
    double? height,
    double? right,
    double? top,
  }) {
    return Stack(
      children: [
        Positioned.fill(child: child ?? Container()),
        Positioned(
          right: 0,
          width: width != null ? (width + (right ?? 10.px)) : 30.px,
          height: height != null ? (height + (top ?? 10.px)) : 30.px,
          top: 0,
          child: GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                Navigator.pop(context);
              },
              child: Container(
                padding: EdgeInsets.only(right: right ?? 10.px, top: top ?? 10.px),
                child: MyAssetImage("icon_close"),
                width: (width ?? 20.px) + (right ?? 10.px),
                height: (height ?? 20.px) + (top ?? 10.px),
              )),
        ),
      ],
    );
  }
}

abstract class BaseCloseAlertWidget extends StatelessWidget {
  final Widget? child;
  final double? width;
  final double? height;
  final double? right;
  final double? top;

  const BaseCloseAlertWidget({Key? key, this.width, this.height, this.right, this.top, this.child}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Positioned.fill(child: buildContent(context)),
        Positioned(
          right: 0,
          width: width != null ? (width ?? 0 + (right ?? 10.px)) : 30.px,
          height: height != null ? (height ?? 0 + (top ?? 10.px)) : 30.px,
          top: 0,
          child: GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                Navigator.pop(context);
              },
              child: Container(
                padding: EdgeInsets.only(right: right ?? 10.px, top: top ?? 10.px),
                child: MyAssetImage("icon_close"),
                width: (width ?? 20.px) + (right ?? 10.px),
                height: (height ?? 20.px) + (top ?? 10.px),
              )),
        ),
      ],
    );
  }

  Widget buildContent(BuildContext context);
}
